#ifndef CUSTOMCHART_H
#define CUSTOMCHART_H

#include <QWidget>

namespace Ui {
class CustomChart;
}


#include <QWidget>
#include <QVector>

#define LIN_COLOR  QColor(0, 107, 176)
#define TEXT_COLOR QColor(255, 255, 255)
#define BACKGROUND_COLOR QColor(26, 26, 26)
#define BRUSH_COLOR QColor(255, 255, 255, 0)
#define LABEL_COLOR QColor(40,150,120)

enum PointType {
    DATA_POINT = 0,
    SMALL_POINT,
    BIG_POINT,
};

struct CoodRangs{
    double xmin;
    double xmax;
    double ymax;
    double ymin;
};


typedef struct CoorData
{
    QVector<double>dataX;  //横坐标
    QVector<double>dataY;  //纵坐标
}CoorData;



class CustomChart : public QWidget
{
    Q_OBJECT

public:
    explicit CustomChart(QWidget *parent = nullptr);
    ~CustomChart();
    void setControlData(const CoorData &coorData);  //设置坐标系

    void setZoom(bool canZoom);                     // 设置可缩放模式
    void setXRange(double lower,double upper);
    void setYRange(double lower,double upper);      // 设置范围
    void setStep(bool isx,double);                  // 设置间距
    void setTimeCoorX();                            // 设置时间轴
    void updateCoor();                              // 通知UI刷新
    void appendValue(double x,double y);            // 增加一个点
    void removeValue(double key);                   // 剔掉一个点
    void setPenColor(QColor color);                 // 设置画笔颜色
    void setShowPoint(int);                         // 设置点的模式
    void setLineStyle(int);                         // 设置线的样式

    CoodRangs getRangs(){                           // 获取坐标轴的范围
        return this->rangs;
    }

private:
    Ui::CustomChart *ui;
    CoorData pointData;
    CoodRangs rangs;


private:
    void initValue();
    bool eventFilter(QObject *watched, QEvent *event) override;
    QPoint matchPoint(QPoint point);
};

#endif // CUSTOMCHART_H
